const n_format=(item)=>{
    if(item>10000){
      let w = (item / 10000).toFixed(0);
        let k =item % 10000;
      if(k > 1000){
         k = (k / 1000).toFixed(0);
         return w+"."+k+"w";
      }
      return w+"w";
    }else if(item>1000){
       let k =  (item / 1000).toFixed(0);
        let h =  item % 1000;
        if(h > 100){
            h = (h / 1000).toFixed(0);
            return k+"."+h+"k";
        }
        return k+"k";
    }
    return item;
}


//根据QQ邮箱获取头像
const avatar = (url) => {
    return 'https://q1.qlogo.cn/g?b=qq&nk=' + url + '&s=640';
};

//获取浏览器类型，获取图片
const platform = () => {
    let systems = "";
    //获取浏览器用户使用的浏览器型号系统信息
    const userAgent = navigator.userAgent;
    if (userAgent.indexOf("Windows") !== -1)  systems = "/img/win.png";
    else if (userAgent.indexOf("Mac") !== -1) systems = "/img/macOS.png";
    else if (userAgent.indexOf("X11") !== -1) systems = "UNIX";
    else if (userAgent.indexOf("Linux") !== -1)
        systems ="/img/linux.png";
    else
        systems = "Other";
    window.localStorage.setItem("systems", systems);
    let mb = myBrowser();
    let browser = "";
    if ("IE" == mb) {
        browser ="/img/ie.png";
    }
    if ("FF" == mb) {
        browser="Other";
    }
    if ("Chrome" == mb) {
        browser="/img/chrome.png";
    }
    if ("Opera" == mb) {
        browser="Other";
    }
    if ("Safari" == mb) {
        browser="/img/safari.png";
    }
    window.localStorage.setItem("browser", browser);
};
//根据浏览器类型获取字符串
const myBrowser = () => {
    let userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    let isOpera = userAgent.indexOf("Opera") > -1;
    if (isOpera) {
        return "Opera"
    } //判断是否Opera浏览器
    if (userAgent.indexOf("Firefox") > -1) {
        return "FF";
    } //判断是否Firefox浏览器
    if (userAgent.indexOf("Chrome") > -1) {
        return "Chrome";
    }
    if (userAgent.indexOf("Safari") > -1) {
        return "Safari";
    } //判断是否Safari浏览器
    if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
        return "IE";
    } //判断是否IE浏览器
};

export default {n_format,avatar,platform }